package com.palm.hubo2o.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import com.palm.hubo2o.model.Issue;
import com.palm.hubo2o.util.EnumCode;
import com.palm.hubo2o.view.PrizeView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dest1 on 2015/10/13.
 */
public class PrizeListAdapter extends RecyclerView.Adapter<PrizeAdapter.PrizeHolder> {
    private EnumCode.gameId lottery_tag;
    private List<Issue> mList;
    private static final int TYPE_SSQ = 0;
    private static final int TYPE_QLC = 1;
    private static final int TYPE_3D = 2;
    private static final int TYPE_K3 = 3;
    private static final int TYPE_225 = 4;

    public void setGameId(EnumCode.gameId tag) {
        lottery_tag = tag;
    }

    public void setIssues(List<Issue> list) {
        if (mList == null) {
            mList = new ArrayList<>();
            mList.addAll(list);
        }
        mList.clear();
        mList.addAll(list);
        notifyDataSetChanged();
    }

    public void updateIssues(List<Issue> list) {
        if (mList == null) {
            mList = new ArrayList<>();
        }
        mList.addAll(list);
        notifyItemRangeChanged(mList.size() - list.size(), list.size());
    }

    public List<Issue> getIssues() {
        return mList;
    }

    @Override
    public PrizeAdapter.PrizeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        PrizeView prizeView = new PrizeView(parent.getContext());
        prizeView.showName(false);
        prizeView.createBalls(lottery_tag);
        prizeView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        return new PrizeAdapter.PrizeHolder(prizeView);
    }

    @Override
    public void onBindViewHolder(PrizeAdapter.PrizeHolder holder, int position) {
        PrizeView prizeView = holder.prizeView;
        if (position == 0) {
            prizeView.setBallsChecked(true);
        } else {
            prizeView.setBallsChecked(false);

        }
        prizeView.setIssue(mList.get(position).issueNo);
        prizeView.setDate(mList.get(position).prizeTime);
        prizeView.setBalls(mList.get(position));

    }

    @Override
    public int getItemCount() {
        if (mList == null)
            return 0;
        return mList.size();
    }


}
